<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.4.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/M.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/M.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/M.png">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">
  <link rel="stylesheet" href="/lib/pace/pace-theme-minimal.min.css">
  <script src="/lib/pace/pace.min.js"></script>

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"maureen-liu.gitee.io","root":"/","scheme":"Gemini","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":true,"show_result":true,"style":null},"back2top":{"enable":true,"sidebar":true,"scrollpercent":true},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":"valine","storage":true,"lazyload":false,"nav":null,"activeClass":"valine"},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="一、导读">
<meta property="og:type" content="article">
<meta property="og:title" content="C++程序设计（part II）兼谈对象模型">
<meta property="og:url" content="https://maureen-liu.gitee.io/p/29d8738c.html">
<meta property="og:site_name" content="Maureen&#39;s blog">
<meta property="og:description" content="一、导读">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211117222501311.png">
<meta property="og:image" content="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211117222608552.png">
<meta property="og:image" content="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211117222733280.png">
<meta property="og:image" content="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211117222744207.png">
<meta property="og:image" content="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211117222754306.png">
<meta property="og:image" content="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211117223844768.png">
<meta property="og:image" content="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122113914290.png">
<meta property="og:image" content="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122112246117.png">
<meta property="og:image" content="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122112530002.png">
<meta property="og:image" content="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122112909223.png">
<meta property="og:image" content="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122114328298.png">
<meta property="og:image" content="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122122017748.png">
<meta property="og:image" content="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122122028504.png">
<meta property="og:image" content="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122123506712.png">
<meta property="og:image" content="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122124430517.png">
<meta property="og:image" content="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122124506718.png">
<meta property="og:image" content="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122124602983.png">
<meta property="og:image" content="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122145251519.png">
<meta property="og:image" content="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122145427946.png">
<meta property="og:image" content="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122145502153.png">
<meta property="og:image" content="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122145529392.png">
<meta property="og:image" content="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122145546246.png">
<meta property="og:image" content="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122150733964.png">
<meta property="og:image" content="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122151510442.png">
<meta property="og:image" content="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122151607892.png">
<meta property="og:image" content="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122151641574.png">
<meta property="og:image" content="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122151740404.png">
<meta property="og:image" content="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122151751301.png">
<meta property="og:image" content="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122151812228.png">
<meta property="og:image" content="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122154814461.png">
<meta property="og:image" content="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122162014523.png">
<meta property="og:image" content="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122162512797.png">
<meta property="og:image" content="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122162611773.png">
<meta property="og:image" content="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122162738876.png">
<meta property="og:image" content="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122164059393.png">
<meta property="og:image" content="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122164531117.png">
<meta property="og:image" content="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122165051236.png">
<meta property="og:image" content="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122170012137.png">
<meta property="og:image" content="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122170228535.png">
<meta property="og:image" content="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122171114306.png">
<meta property="og:image" content="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122171158600.png">
<meta property="og:image" content="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122171253474.png">
<meta property="og:image" content="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122171321530.png">
<meta property="og:image" content="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122171517893.png">
<meta property="og:image" content="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122171539825.png">
<meta property="og:image" content="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122171609113.png">
<meta property="og:image" content="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122171644572.png">
<meta property="og:image" content="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122171701645.png">
<meta property="og:image" content="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122195257289.png">
<meta property="og:image" content="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122195429940.png">
<meta property="og:image" content="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122202414403.png">
<meta property="og:image" content="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122202814003.png">
<meta property="og:image" content="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122203014683.png">
<meta property="og:image" content="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122203138952.png">
<meta property="og:image" content="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122203301307.png">
<meta property="og:image" content="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122203804170.png">
<meta property="og:image" content="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122204903877.png">
<meta property="og:image" content="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122205052168.png">
<meta property="og:image" content="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122205206493.png">
<meta property="og:image" content="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122205221736.png">
<meta property="og:image" content="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122210625502.png">
<meta property="article:published_time" content="2021-11-22T03:06:45.000Z">
<meta property="article:modified_time" content="2021-11-23T08:48:49.901Z">
<meta property="article:author" content="Maureen">
<meta property="article:tag" content="侯捷">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211117222501311.png">

<link rel="canonical" href="https://maureen-liu.gitee.io/p/29d8738c.html">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>
<script src="/lib/fireworks.js"></script>
  <title>C++程序设计（part II）兼谈对象模型 | Maureen's blog</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">Maureen's blog</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">记录学习的点点滴滴</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://maureen-liu.gitee.io/p/29d8738c.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/stan.jpeg">
      <meta itemprop="name" content="Maureen">
      <meta itemprop="description" content="心之所向，素履以往">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Maureen's blog">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          C++程序设计（part II）兼谈对象模型
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2021-11-22 11:06:45" itemprop="dateCreated datePublished" datetime="2021-11-22T11:06:45+08:00">2021-11-22</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2021-11-23 16:48:49" itemprop="dateModified" datetime="2021-11-23T16:48:49+08:00">2021-11-23</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/C/" itemprop="url" rel="index"><span itemprop="name">C++</span></a>
                </span>
                  ，
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/C/%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1%E9%AB%98%E7%BA%A7%E5%BC%80%E5%8F%91/" itemprop="url" rel="index"><span itemprop="name">面向对象高级开发</span></a>
                </span>
            </span>

          
            <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv" style="display: none;">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span id="busuanzi_value_page_pv"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="far fa-comment"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/p/29d8738c.html#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/p/29d8738c.html" itemprop="commentCount"></span>
    </a>
  </span>
  
  <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>6k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>5 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
      
      
        <h1 id="一-导读"><a class="markdownIt-Anchor" href="#一-导读"></a> 一、导读</h1>
<span id="more"></span>
<p><img src="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211117222501311.png" alt="image-20211117222501311"></p>
<p>目标：</p>
<p><img src="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211117222608552.png" alt="image-20211117222608552"></p>
<p>书籍推荐：</p>
<p><img src="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211117222733280.png" alt="image-20211117222733280"></p>
<p><img src="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211117222744207.png" alt="image-20211117222744207"></p>
<p><img src="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211117222754306.png" alt="image-20211117222754306"></p>
<h1 id="二-转换函数"><a class="markdownIt-Anchor" href="#二-转换函数"></a> 二、转换函数</h1>
<h2 id="21-conversion-function转换函数"><a class="markdownIt-Anchor" href="#21-conversion-function转换函数"></a> 2.1 conversion function，转换函数</h2>
<p>示例：<code>Fraction</code> 转换为 <code>double</code></p>
<p><img src="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211117223844768.png" alt="image-20211117223844768"></p>
<ul>
<li><code>double</code> 函数不可以有参数；没有返回类型；</li>
<li>函数名称一定是<code>operator type()</code>；</li>
<li>只要合理，一个类可以设计多个转换函数。</li>
</ul>
<p>编译器在编译上面的代码时，在处理这行代码：</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">double</span> d = <span class="number">4</span> + f;</span><br></pre></td></tr></table></figure>
<p>的时候，会先查看是否有写函数<code>Fraction operator+(double, Fraction&amp;)</code>，目前的代码中没有这个函数，于是编译器就另寻他路，看是否能将 <code>f</code> 转换为 <code>double</code>，就会到代码中查看是否设计了转换函数，然后就发现了<code>operator double()</code> 这个转换函数。于是编译器就将<code>f</code> 转换为 <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mn>3</mn><mi mathvariant="normal">/</mi><mn>5</mn><mo>=</mo><mn>0.6</mn></mrow><annotation encoding="application/x-tex">3/5 = 0.6</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord">3</span><span class="mord">/</span><span class="mord">5</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.64444em;vertical-align:0em;"></span><span class="mord">0</span><span class="mord">.</span><span class="mord">6</span></span></span></span>，所以最终的结果 <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>d</mi><mo>=</mo><mn>4.6</mn></mrow><annotation encoding="application/x-tex">d = 4.6</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.69444em;vertical-align:0em;"></span><span class="mord mathdefault">d</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.64444em;vertical-align:0em;"></span><span class="mord">4</span><span class="mord">.</span><span class="mord">6</span></span></span></span>。</p>
<p>正确的代码应该如下：</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/*************************************************************************</span></span><br><span class="line"><span class="comment">	&gt; File Name: 001.Fraction_to_double.cpp</span></span><br><span class="line"><span class="comment">	&gt; Author: Maureen </span></span><br><span class="line"><span class="comment">	&gt; Mail: Maureen@qq.com </span></span><br><span class="line"><span class="comment">	&gt; Created Time: 三 11/17 23:52:46 2021</span></span><br><span class="line"><span class="comment"> ************************************************************************/</span></span><br><span class="line"></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> std;</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Fraction</span> </span></span><br><span class="line"><span class="class">&#123;</span></span><br><span class="line"><span class="keyword">public</span>:</span><br><span class="line">    <span class="built_in">Fraction</span>(<span class="keyword">int</span> num, <span class="keyword">int</span> den = <span class="number">1</span>) : <span class="built_in">m_numerator</span>(num), <span class="built_in">m_denominator</span>(den) &#123;&#125;</span><br><span class="line">    <span class="function"><span class="keyword">operator</span> <span class="title">double</span><span class="params">()</span> <span class="keyword">const</span> </span>&#123;</span><br><span class="line">        cout &lt;&lt; <span class="string">&quot;double function is called&quot;</span> &lt;&lt; endl;</span><br><span class="line">        <span class="keyword">return</span> ((<span class="keyword">double</span>)m_numerator / m_denominator);</span><br><span class="line">    &#125;</span><br><span class="line"><span class="keyword">private</span>:</span><br><span class="line">    <span class="keyword">int</span> m_numerator;</span><br><span class="line">    <span class="keyword">int</span> m_denominator;</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>&#123;</span><br><span class="line">    <span class="function">Fraction <span class="title">f</span><span class="params">(<span class="number">3</span>, <span class="number">5</span>)</span></span>;</span><br><span class="line">    <span class="keyword">double</span> d = <span class="number">4</span> + f;</span><br><span class="line">    cout &lt;&lt; <span class="string">&quot;f = &quot;</span> &lt;&lt; f &lt;&lt; endl; <span class="comment">//0.6</span></span><br><span class="line">    cout &lt;&lt; <span class="string">&quot;d = &quot;</span> &lt;&lt; d &lt;&lt; endl; <span class="comment">//4.6</span></span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>标准库中的应用：</p>
<p><img src="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122113914290.png" alt="image-20211122113914290"></p>
<p><code>reference operator[]</code> 函数要返回一个 <code>bool</code> 值，则 <code>reference</code> 类型中一定有个转换函数将结果转换为<code>bool</code> 值类型，果然，在<code>__bit_reference</code> 中有个转换函数 <code>operator bool() const</code>。</p>
<h2 id="22-non-span-stylecolorblueexplicitspan-one-argument-ctor"><a class="markdownIt-Anchor" href="#22-non-span-stylecolorblueexplicitspan-one-argument-ctor"></a> 2.2 non-<span style="color:blue">explicit</span>-one-argument ctor</h2>
<p>此处的<code>one-argument</code>是指至少有一个实参，若有多个实参也可以。</p>
<p>示例：将<code>double</code>转换为<code>Fraction</code></p>
<p><img src="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122112246117.png" alt="image-20211122112246117"></p>
<h2 id="23-conversion-function-vs-non-span-styleblueexplicitspan-one-argument-ctor"><a class="markdownIt-Anchor" href="#23-conversion-function-vs-non-span-styleblueexplicitspan-one-argument-ctor"></a> 2.3 conversion function vs. non-<span style="blue">explicit</span>-one-argument ctor</h2>
<p><img src="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122112530002.png" alt="image-20211122112530002"></p>
<p>绿色的部分可以将 4 转换为 <code>Fraction</code>，黄色部分可以将 <code>f</code> 转换为 <code>double</code>。这两条路径都可行，产生了歧义，所以编译器不知道应该选择哪个路径。</p>
<h2 id="24-span-stylecolorblueexplicitspan-one-argument-ctor"><a class="markdownIt-Anchor" href="#24-span-stylecolorblueexplicitspan-one-argument-ctor"></a> 2.4 <span style="color:blue">explicit</span>-one-argument ctor</h2>
<p><code>explicit</code> 关键字的意思是告诉编译器，不要将 4 自动转换为 <code>4/1</code>。</p>
<p><img src="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122112909223.png" alt="image-20211122112909223"></p>
<p>此处的<code>+</code> 要将<code>4</code> 转换为 <code>Fraction</code> 类型，但是因为构造函数加了 <code>explicit</code>关键字，所以 4 无法转换为 <code>Fraction</code>，因此出现错误。</p>
<p>百分之九十的情况，<code>explicit</code> 关键字出现在构造函数前。</p>
<h1 id="三-智能指针"><a class="markdownIt-Anchor" href="#三-智能指针"></a> 三、智能指针</h1>
<h2 id="31-pointer-like-classes关于智能指针"><a class="markdownIt-Anchor" href="#31-pointer-like-classes关于智能指针"></a> 3.1 pointer-like classes，关于智能指针</h2>
<p>将一个 <code>class</code> 设计出来像一个指针或者函数。</p>
<p><img src="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122114328298.png" alt="image-20211122114328298"></p>
<ul>
<li><code>sp-&gt;method()</code>这行代码，<code>-&gt;</code> 作用于 <code>sp</code>，即调用了 <code>T * operator-&gt;()</code> 函数，得到了 <code>px</code>，而<code>-&gt;</code> 得到的结果如果要继续执行下去就要继续调用 <code>-&gt;</code>，这是 C++ 中 <code>-&gt;</code> 的特性；</li>
<li>智能指针类中一定有指针类型的变量，且一定要写操作符 <code>*</code> 和 <code>-&gt;</code> 的函数，写法一般都是如上所示。</li>
</ul>
<h2 id="32-pointer-like-classes关于迭代器"><a class="markdownIt-Anchor" href="#32-pointer-like-classes关于迭代器"></a> 3.2 pointer-like classes，关于迭代器</h2>
<p>标准库中的链表：</p>
<p><img src="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122122017748.png" alt="image-20211122122017748"></p>
<p><img src="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122122028504.png" alt="image-20211122122028504"></p>
<ul>
<li>迭代器也是智能指针，但是相比较于 <code>shared_ptr</code> 中的操作符重载的写法，有所变化；</li>
<li>迭代器不仅要实现操作符<code>*</code>和 <code>-&gt;</code>，还要实现其他的操作符。</li>
</ul>
<h1 id="四-仿函数"><a class="markdownIt-Anchor" href="#四-仿函数"></a> 四、仿函数</h1>
<h2 id="41-function-class-classes所谓仿函数"><a class="markdownIt-Anchor" href="#41-function-class-classes所谓仿函数"></a> 4.1 function-class classes，所谓仿函数</h2>
<p>设计一个class，让它像一个函数。</p>
<p><img src="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122123506712.png" alt="image-20211122123506712"></p>
<h2 id="42-标准库中的仿函数的奇特模样"><a class="markdownIt-Anchor" href="#42-标准库中的仿函数的奇特模样"></a> 4.2 标准库中的仿函数的奇特模样</h2>
<p><img src="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122124430517.png" alt="image-20211122124430517"></p>
<p><img src="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122124506718.png" alt="image-20211122124506718"></p>
<h2 id="43-标准库中仿函数所使用的奇特的-base-classes"><a class="markdownIt-Anchor" href="#43-标准库中仿函数所使用的奇特的-base-classes"></a> 4.3 标准库中，仿函数所使用的奇特的 base classes</h2>
<p><img src="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122124602983.png" alt="image-20211122124602983"></p>
<h1 id="五-namespace经验谈"><a class="markdownIt-Anchor" href="#五-namespace经验谈"></a> 五、namespace经验谈</h1>
<p><img src="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122145251519.png" alt="image-20211122145251519"></p>
<h1 id="六-模板"><a class="markdownIt-Anchor" href="#六-模板"></a> 六、模板</h1>
<h2 id="61-class-template类模板"><a class="markdownIt-Anchor" href="#61-class-template类模板"></a> 6.1 class template，类模板</h2>
<p><img src="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122145427946.png" alt="image-20211122145427946"></p>
<ul>
<li>类模板使用的时候需要指定类型</li>
</ul>
<h2 id="62-function-template函数模板"><a class="markdownIt-Anchor" href="#62-function-template函数模板"></a> 6.2 function template，函数模板</h2>
<p><img src="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122145502153.png" alt="image-20211122145502153"></p>
<ul>
<li>此处的<code>template &lt;class T&gt;</code>中的 <code>class</code>，可以修改为 <code>typename</code>；</li>
<li>使用函数模板的时候不需要指定类型；</li>
<li>模板会编译一次，实际使用的时候会再编译一次；</li>
</ul>
<h2 id="63-member-template成员模板"><a class="markdownIt-Anchor" href="#63-member-template成员模板"></a> 6.3 member template，成员模板</h2>
<p><img src="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122145529392.png" alt="image-20211122145529392"></p>
<p><img src="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122145546246.png" alt="image-20211122145546246"></p>
<p>问：把一个由鲫鱼和麻雀构成的 <code>pairt</code>，放进（拷贝到）一个由鱼类和鸟类构成的 <code>pair</code> 中，可以吗？</p>
<p>答：可以。</p>
<p>问：反之，可以吗？</p>
<p>答：不可以。</p>
<p><img src="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122150733964.png" alt="image-20211122150733964"></p>
<h2 id="64-specialization模板特化"><a class="markdownIt-Anchor" href="#64-specialization模板特化"></a> 6.4 specialization，模板特化</h2>
<p><img src="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122151510442.png" alt="image-20211122151510442"></p>
<h2 id="65-partial-specialization模板span-stylecolorred偏span特化-span-stylecolorblue个数span的偏"><a class="markdownIt-Anchor" href="#65-partial-specialization模板span-stylecolorred偏span特化-span-stylecolorblue个数span的偏"></a> 6.5 partial specialization，模板<span style="color:red">偏</span>特化—— <span style="color:blue">个数</span>的偏</h2>
<p><img src="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122151607892.png" alt="image-20211122151607892"></p>
<h2 id="66-partial-specialization模板span-stylecolorred偏span特化-span-stylecolorblue范围span的偏"><a class="markdownIt-Anchor" href="#66-partial-specialization模板span-stylecolorred偏span特化-span-stylecolorblue范围span的偏"></a> 6.6 partial specialization，模板<span style="color:red">偏</span>特化—— <span style="color:blue">范围</span>的偏</h2>
<p><img src="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122151641574.png" alt="image-20211122151641574"></p>
<ul>
<li>所谓的”范围的偏“，指的是之前的泛化版本是任意类型，而偏特化版本是指针类型；</li>
<li><code>C&lt;string&gt; obj1;</code> 使用的是泛化版本；</li>
<li><code>C&lt;string*&gt; obj2;</code> 使用的是偏特化版本，因为是指针类型。</li>
</ul>
<h2 id="67-template-template-parameter模板模板参数"><a class="markdownIt-Anchor" href="#67-template-template-parameter模板模板参数"></a> 6.7 template template parameter，模板模板参数</h2>
<p><img src="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122151740404.png" alt="image-20211122151740404"></p>
<ul>
<li>容器中的类型未定，容器本身就是个模板；</li>
<li>容器还有其他模板参数，平时没有写是因为有默认值；</li>
</ul>
<p><img src="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122151751301.png" alt="image-20211122151751301"></p>
<ul>
<li>此处的两个×不是模板模板参数有错，而是智能指针<code>unique_ptr</code>和 <code>weak_ptr</code> 的特性导致此处的错误。</li>
</ul>
<p><span style="font-Size:30px;">这不是 template template parameter</span></p>
<p><img src="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122151812228.png" alt="image-20211122151812228"></p>
<ul>
<li>使用第二模板参数的时候，必须写成<code>list&lt;int&gt;</code>，因为已经绑定了<code>int</code>，不再是模糊的，所以它不是模板模板参数。</li>
</ul>
<h1 id="七-关于c标准库"><a class="markdownIt-Anchor" href="#七-关于c标准库"></a> 七、关于C++标准库</h1>
<p><img src="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122154814461.png" alt="image-20211122154814461"></p>
<h1 id="八-更多细节深入"><a class="markdownIt-Anchor" href="#八-更多细节深入"></a> 八、更多细节深入</h1>
<p><img src="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122162014523.png" alt="image-20211122162014523"></p>
<h1 id="九-c20"><a class="markdownIt-Anchor" href="#九-c20"></a> 九、C++2.0</h1>
<h2 id="91-了解你的编译器对c20的支持度"><a class="markdownIt-Anchor" href="#91-了解你的编译器对c20的支持度"></a> 9.1 了解你的编译器对C++2.0的支持度</h2>
<p><img src="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122162512797.png" alt="image-20211122162512797"></p>
<h2 id="92-确认支持c11marco-span-stylecolororange__cplusplusspan"><a class="markdownIt-Anchor" href="#92-确认支持c11marco-span-stylecolororange__cplusplusspan"></a> 9.2 确认支持C++11：marco <span style="color:orange">__cplusplus</span></h2>
<p><img src="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122162611773.png" alt="image-20211122162611773"></p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/*************************************************************************</span></span><br><span class="line"><span class="comment">	&gt; File Name: test.cpp</span></span><br><span class="line"><span class="comment">	&gt; Author: Maureen</span></span><br><span class="line"><span class="comment">	&gt; Mail: Maureen@qq.com</span></span><br><span class="line"><span class="comment">	&gt; Created Time: 一 11/22 16:23:29 2021</span></span><br><span class="line"><span class="comment"> ************************************************************************/</span></span><br><span class="line"></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> std;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span> </span>&#123;</span><br><span class="line">    cout &lt;&lt; __cplusplus &lt;&lt; endl; <span class="comment">//201103</span></span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="93-三大主题"><a class="markdownIt-Anchor" href="#93-三大主题"></a> 9.3 三大主题</h2>
<h3 id="931-variadic-templatessince-c11"><a class="markdownIt-Anchor" href="#931-variadic-templatessince-c11"></a> 9.3.1 variadic templates（since C++11）</h3>
<p>数量不定的模板参数</p>
<p><img src="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122162738876.png" alt="image-20211122162738876"></p>
<p><code>sizeof...(args)</code> 可以获得<code>pack</code>里的参数个数。</p>
<p>完整代码：</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/*************************************************************************</span></span><br><span class="line"><span class="comment">	&gt; File Name: 02.variadic_templates.cpp</span></span><br><span class="line"><span class="comment">	&gt; Author: Maureen </span></span><br><span class="line"><span class="comment">	&gt; Mail: Maureen@qq.com </span></span><br><span class="line"><span class="comment">	&gt; Created Time: 一 11/22 16:36:59 2021</span></span><br><span class="line"><span class="comment"> ************************************************************************/</span></span><br><span class="line"></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> std;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">print</span><span class="params">()</span> </span>&#123;  &#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">template</span> &lt;<span class="keyword">typename</span> T, <span class="keyword">typename</span>... Types&gt;</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">print</span><span class="params">(<span class="keyword">const</span> T&amp; firstArg, <span class="keyword">const</span> Types&amp;... args)</span> </span>&#123;</span><br><span class="line">    <span class="comment">//cout &lt;&lt; &quot;pack numbers: &quot; &lt;&lt; sizeof...(args) &lt;&lt; endl;</span></span><br><span class="line">    cout &lt;&lt; firstArg &lt;&lt; endl;</span><br><span class="line">    <span class="built_in">print</span>(args...);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span> </span>&#123;</span><br><span class="line">    <span class="built_in">print</span>(<span class="number">7.5</span>, <span class="string">&quot;hello&quot;</span>, bitset&lt;<span class="number">16</span>&gt;(<span class="number">377</span>), <span class="number">42</span>);</span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="932-autosince-c11"><a class="markdownIt-Anchor" href="#932-autosince-c11"></a> 9.3.2 auto(since C++11)</h3>
<p><img src="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122164059393.png" alt="image-20211122164059393"></p>
<p><code>auto ite;</code>没有赋值的时候，编译器是无法推导出 <code>ite</code> 的类型的，所以使用错误。</p>
<h3 id="933-ranged-base-span-stylecolorblueforspan-since-c11"><a class="markdownIt-Anchor" href="#933-ranged-base-span-stylecolorblueforspan-since-c11"></a> 9.3.3 ranged-base <span style="color:blue">for</span> (since C++11)</h3>
<p><img src="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122164531117.png" alt="image-20211122164531117"></p>
<p>如果要改变原来的值就使用引用。</p>
<h2 id="94-reference"><a class="markdownIt-Anchor" href="#94-reference"></a> 9.4 reference</h2>
<p><img src="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122165051236.png" alt="image-20211122165051236"></p>
<ul>
<li>reference一定要设初值，说明它代表什么东西；自此之后，reference就不能代表其它了；</li>
<li>reference底层有个指针指向它所代表的东西；</li>
</ul>
<p>示例：</p>
<p><img src="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122170012137.png" alt="image-20211122170012137"></p>
<h2 id="95-reference的常见用途"><a class="markdownIt-Anchor" href="#95-reference的常见用途"></a> 9.5 reference的常见用途</h2>
<p><img src="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122170228535.png" alt="image-20211122170228535"></p>
<ul>
<li>引用的底层是用指针实现的，所以当传的数据很大的时候，通过引用传递速度更快；</li>
<li>签名不包含 return type。</li>
</ul>
<p><img src="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122171114306.png" alt="image-20211122171114306"></p>
<h1 id="十-object-model"><a class="markdownIt-Anchor" href="#十-object-model"></a> 十、object model</h1>
<p>回顾：</p>
<ol>
<li>Composition（复合）关系下的构造和析构</li>
</ol>
<p><img src="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122171158600.png" alt="image-20211122171158600"></p>
<ol start="2">
<li>Inheritance（继承）关系下的构造和析构</li>
</ol>
<p><img src="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122171253474.png" alt="image-20211122171253474"></p>
<ol start="3">
<li>Inheritance+Composition关系下的析构和构造</li>
</ol>
<p><img src="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122171321530.png" alt="image-20211122171321530"></p>
<h2 id="101-对象模型object-model关于-vptr-和-vtbl"><a class="markdownIt-Anchor" href="#101-对象模型object-model关于-vptr-和-vtbl"></a> 10.1 对象模型（Object Model）：关于 vptr 和 vtbl</h2>
<p>虚指针和虚表。</p>
<p><img src="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122171517893.png" alt="image-20211122171517893"></p>
<ul>
<li>子类中有父类的成分；子类不仅会继承父类的数据，还会继承函数的调用权利；</li>
<li><span style="color:red">如果类中有虚函数，类就会多一个指针的大小，即虚指针；</span></li>
<li>不管类中有多少个虚函数，都只有一个虚指针<code>vptr</code>，指向虚函数表<code>vtbl</code>；<code>vtbl</code> 中放置的是函数指针；</li>
<li>如果父类有虚函数，子类也一定有虚函数；</li>
<li><code>B</code> 继承了 <code>A</code>，所以<code>B</code> 继承了<code>A</code> 的虚函数，<code>B</code> 中也有两个虚函数<code>vfunc1</code>和 <code>vfunc2</code>，只是<code>B</code> 又重写了方法<code>vfunc1</code>；</li>
<li>“从 <code>p</code> 到 <code>ptr</code> 到 <code>vtbl</code> 到 某个方法的流程” 编译器解析出来就是 <code>(*(p-&gt;vptr)[n])(p);</code> 或者 <code>(* p-&gt;vptr[n])(p);</code></li>
</ul>
<p><img src="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122171539825.png" alt="image-20211122171539825"></p>
<ul>
<li>为了放置不同大小的形状，所以要放入指针，指向父类；</li>
<li>希望做到：遍历容器，调用每个指针所指向的<code>draw</code>；所以<code>draw</code>必须是虚函数，才能实现这种功能；</li>
<li>虚函数的这种用法叫做多态（<em>polymorphism</em>）；</li>
</ul>
<p>总结：C++编译器处理函数调用的时候，要考虑是<strong>静态绑定</strong>还是<strong>动态绑定</strong>。</p>
<ul>
<li>静态绑定被编译成<code>call xxx</code>，其中的<code>xxx</code> 是函数地址；</li>
<li>如果符合以下三个条件就会进行动态绑定：① 必须通过指针调用；②指针是向上转型的<code>up-cast</code>；③调用的是虚函数。编译器会将其编译成 <code>(*(p-&gt;vptr)[n])(p);</code> 或者 <code>(* p-&gt;vptr[n])(p);</code>，具体调用的是哪个函数要看<code>p</code> 指向的是什么。</li>
</ul>
<p>多态、虚函数和动态绑定其实都是一回事。</p>
<h2 id="102-对象模型object-model关于-this"><a class="markdownIt-Anchor" href="#102-对象模型object-model关于-this"></a> 10.2 对象模型（Object Model）：关于 this</h2>
<p><img src="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122171609113.png" alt="image-20211122171609113"></p>
<ul>
<li>
<p>通过某个对象调用函数，则该对象的地址就是<code>this</code>；</p>
</li>
<li>
<p>上述的是模板方法(Template Method)；</p>
</li>
<li>
<p><code>this-&gt;Serialize();</code> 函数满足动态绑定的三个条件，所以编译器会进行动态绑定；</p>
</li>
</ul>
<h2 id="103-对象模型object-model关于dynamic-binding"><a class="markdownIt-Anchor" href="#103-对象模型object-model关于dynamic-binding"></a> 10.3 对象模型（Object Model）：关于Dynamic Binding</h2>
<p><img src="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122171644572.png" alt="image-20211122171644572"></p>
<ul>
<li>此处的<code>a.vfunc1()</code>，通过对象调用函数，所以是<em>静态绑定</em>；</li>
</ul>
<p><img src="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122171701645.png" alt="image-20211122171701645"></p>
<ul>
<li>此处的虚函数调用，满足动态绑定过的三个条件，是<em>动态绑定</em>。</li>
</ul>
<h1 id="十一-谈谈const"><a class="markdownIt-Anchor" href="#十一-谈谈const"></a> 十一、谈谈const</h1>
<p><img src="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122195257289.png" alt="image-20211122195257289"></p>
<ul>
<li><code>const</code>修饰成员函数是为了告诉编译器这个成员函数不打算修改类中的成员数据的意图，请编译器帮忙把关是否违反了这个意图。</li>
</ul>
<p><img src="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122195429940.png" alt="image-20211122195429940"></p>
<ul>
<li><code>const</code> 属于签名；</li>
<li>如果涉及到引用，可能就会有共享，为了防止被修改，就要拷贝一份进行修改，即涉及到共享，就要考虑<code>Copy On Write</code>;</li>
<li>常量字符串不必考虑<code>Copy On Write</code>；</li>
</ul>
<h1 id="十二-关于newdelete"><a class="markdownIt-Anchor" href="#十二-关于newdelete"></a> 十二、关于new，delete</h1>
<h2 id="121-回顾"><a class="markdownIt-Anchor" href="#121-回顾"></a> 12.1 回顾</h2>
<p><img src="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122202414403.png" alt="image-20211122202414403"></p>
<ul>
<li>类中的<code>new</code> 和 <code>delete</code> 都可以进行重载，可用于内存池的设计；</li>
</ul>
<h2 id="122-重载operator-new-opeartor-delete-operator-new-operator-delete"><a class="markdownIt-Anchor" href="#122-重载operator-new-opeartor-delete-operator-new-operator-delete"></a> 12.2 重载::operator new, ::opeartor delete, ::operator new[], ::operator delete[]</h2>
<p><img src="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122202814003.png" alt="image-20211122202814003"></p>
<h2 id="123-重载member-operator-newdelete"><a class="markdownIt-Anchor" href="#123-重载member-operator-newdelete"></a> 12.3 重载member operator new/delete</h2>
<p><img src="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122203014683.png" alt="image-20211122203014683"></p>
<ul>
<li>重载的函数会接管<code>new</code>/<code>delete</code> 分解后的步骤中的相同函数名的函数</li>
</ul>
<h2 id="124-重载member-operator-newdelete"><a class="markdownIt-Anchor" href="#124-重载member-operator-newdelete"></a> 12.4 重载member operator new[]/delete[]</h2>
<p><img src="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122203138952.png" alt="image-20211122203138952"></p>
<h2 id="125-示例"><a class="markdownIt-Anchor" href="#125-示例"></a> 12.5 示例</h2>
<p><img src="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122203301307.png" alt="image-20211122203301307"></p>
<p>说明：</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">Foo* pf = <span class="keyword">new</span> Foo;</span><br><span class="line"><span class="keyword">delete</span> pf;</span><br></pre></td></tr></table></figure>
<p>如果没有重载运算符<code>new</code>和<code>delete</code>的成员函数，就调用全局的<code>operator new</code>；</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">Foo* pf = ::<span class="keyword">new</span> Foo;</span><br><span class="line">::<span class="keyword">delete</span> pf;</span><br></pre></td></tr></table></figure>
<p>无论是否有重载运算符<code>new</code>和<code>delete</code>的成员函数，都调用全局的<code>operator new</code>。</p>
<p><img src="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122203804170.png" alt="image-20211122203804170"></p>
<ul>
<li><code>Foo with virtual dtor</code> 的 <code>size</code> 比 <code>Foo without virtual dtor</code> 的 <code>size</code> 大 4 的原因是，类中如果有虚函数，就会多一个虚指针，在32bit机器上占 4 个字节；</li>
<li><code>Foo* pArray = new Foo[5]</code> 的大小为 64， 其中多出来的 4 是计数counter，表示有5个元素，将 “array 的整包大小 + 一个计数的counter” 进行分配；</li>
</ul>
<p><img src="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122204903877.png" alt="image-20211122204903877"></p>
<ul>
<li>无论是否调用的是重载的<code>new</code>和<code>delete</code> 函数，在数组的前面加一个 counter 的逻辑是不会变的</li>
</ul>
<h2 id="126-重载-new-delete"><a class="markdownIt-Anchor" href="#126-重载-new-delete"></a> 12.6 重载 new(), delete()</h2>
<p><img src="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122205052168.png" alt="image-20211122205052168"></p>
<p><img src="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122205206493.png" alt="image-20211122205206493"></p>
<p><img src="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122205221736.png" alt="image-20211122205221736"></p>
<h2 id="127-basic_string-使用-newextra-扩充申请量"><a class="markdownIt-Anchor" href="#127-basic_string-使用-newextra-扩充申请量"></a> 12.7 basic_string 使用 new(<em>extra</em>) 扩充申请量</h2>
<p>标准库中 <code>placement new</code> 的例子：</p>
<p><img src="https://gitee.com/maureen-liu/typora-image/raw/master/typora-image/image-20211122210625502.png" alt="image-20211122210625502"></p>


      <div>
        
        <div>
    
        <div style="text-align:center;color: #ccc;font-size:14px;">-------------本文结束<i class="fa fa-paw"></i>感谢您的阅读-------------</div>
    
</div>


        
      </div>

    </div>

    
    
    
        

<div>
<ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者： </strong>Maureen
  </li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="https://maureen-liu.gitee.io/p/29d8738c.html" title="C++程序设计（part II）兼谈对象模型">https://maureen-liu.gitee.io/p/29d8738c.html</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" rel="noopener" target="_blank"><i class="fab fa-fw fa-creative-commons"></i>BY-NC-SA</a> 许可协议。转载请注明出处！
  </li>
</ul>
</div>


      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/%E4%BE%AF%E6%8D%B7/" rel="tag"># 侯捷</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/p/16107.html" rel="prev" title="Hello World">
      <i class="fa fa-chevron-left"></i> Hello World
    </a></div>
      <div class="post-nav-item">
    <a href="/p/46598833.html" rel="next" title="C++面向对象高级编程（part I)">
      C++面向对象高级编程（part I) <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          
    <div class="comments" id="valine-comments"></div>

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>
        
      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%B8%80-%E5%AF%BC%E8%AF%BB"><span class="nav-text"> 一、导读</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%BA%8C-%E8%BD%AC%E6%8D%A2%E5%87%BD%E6%95%B0"><span class="nav-text"> 二、转换函数</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#21-conversion-function%E8%BD%AC%E6%8D%A2%E5%87%BD%E6%95%B0"><span class="nav-text"> 2.1 conversion function，转换函数</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#22-non-span-stylecolorblueexplicitspan-one-argument-ctor"><span class="nav-text"> 2.2 non-explicit-one-argument ctor</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#23-conversion-function-vs-non-span-styleblueexplicitspan-one-argument-ctor"><span class="nav-text"> 2.3 conversion function vs. non-explicit-one-argument ctor</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#24-span-stylecolorblueexplicitspan-one-argument-ctor"><span class="nav-text"> 2.4 explicit-one-argument ctor</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%B8%89-%E6%99%BA%E8%83%BD%E6%8C%87%E9%92%88"><span class="nav-text"> 三、智能指针</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#31-pointer-like-classes%E5%85%B3%E4%BA%8E%E6%99%BA%E8%83%BD%E6%8C%87%E9%92%88"><span class="nav-text"> 3.1 pointer-like classes，关于智能指针</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#32-pointer-like-classes%E5%85%B3%E4%BA%8E%E8%BF%AD%E4%BB%A3%E5%99%A8"><span class="nav-text"> 3.2 pointer-like classes，关于迭代器</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%9B%9B-%E4%BB%BF%E5%87%BD%E6%95%B0"><span class="nav-text"> 四、仿函数</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#41-function-class-classes%E6%89%80%E8%B0%93%E4%BB%BF%E5%87%BD%E6%95%B0"><span class="nav-text"> 4.1 function-class classes，所谓仿函数</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#42-%E6%A0%87%E5%87%86%E5%BA%93%E4%B8%AD%E7%9A%84%E4%BB%BF%E5%87%BD%E6%95%B0%E7%9A%84%E5%A5%87%E7%89%B9%E6%A8%A1%E6%A0%B7"><span class="nav-text"> 4.2 标准库中的仿函数的奇特模样</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#43-%E6%A0%87%E5%87%86%E5%BA%93%E4%B8%AD%E4%BB%BF%E5%87%BD%E6%95%B0%E6%89%80%E4%BD%BF%E7%94%A8%E7%9A%84%E5%A5%87%E7%89%B9%E7%9A%84-base-classes"><span class="nav-text"> 4.3 标准库中，仿函数所使用的奇特的 base classes</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%BA%94-namespace%E7%BB%8F%E9%AA%8C%E8%B0%88"><span class="nav-text"> 五、namespace经验谈</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%85%AD-%E6%A8%A1%E6%9D%BF"><span class="nav-text"> 六、模板</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#61-class-template%E7%B1%BB%E6%A8%A1%E6%9D%BF"><span class="nav-text"> 6.1 class template，类模板</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#62-function-template%E5%87%BD%E6%95%B0%E6%A8%A1%E6%9D%BF"><span class="nav-text"> 6.2 function template，函数模板</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#63-member-template%E6%88%90%E5%91%98%E6%A8%A1%E6%9D%BF"><span class="nav-text"> 6.3 member template，成员模板</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#64-specialization%E6%A8%A1%E6%9D%BF%E7%89%B9%E5%8C%96"><span class="nav-text"> 6.4 specialization，模板特化</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#65-partial-specialization%E6%A8%A1%E6%9D%BFspan-stylecolorred%E5%81%8Fspan%E7%89%B9%E5%8C%96-span-stylecolorblue%E4%B8%AA%E6%95%B0span%E7%9A%84%E5%81%8F"><span class="nav-text"> 6.5 partial specialization，模板偏特化—— 个数的偏</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#66-partial-specialization%E6%A8%A1%E6%9D%BFspan-stylecolorred%E5%81%8Fspan%E7%89%B9%E5%8C%96-span-stylecolorblue%E8%8C%83%E5%9B%B4span%E7%9A%84%E5%81%8F"><span class="nav-text"> 6.6 partial specialization，模板偏特化—— 范围的偏</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#67-template-template-parameter%E6%A8%A1%E6%9D%BF%E6%A8%A1%E6%9D%BF%E5%8F%82%E6%95%B0"><span class="nav-text"> 6.7 template template parameter，模板模板参数</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%B8%83-%E5%85%B3%E4%BA%8Ec%E6%A0%87%E5%87%86%E5%BA%93"><span class="nav-text"> 七、关于C++标准库</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%85%AB-%E6%9B%B4%E5%A4%9A%E7%BB%86%E8%8A%82%E6%B7%B1%E5%85%A5"><span class="nav-text"> 八、更多细节深入</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%B9%9D-c20"><span class="nav-text"> 九、C++2.0</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#91-%E4%BA%86%E8%A7%A3%E4%BD%A0%E7%9A%84%E7%BC%96%E8%AF%91%E5%99%A8%E5%AF%B9c20%E7%9A%84%E6%94%AF%E6%8C%81%E5%BA%A6"><span class="nav-text"> 9.1 了解你的编译器对C++2.0的支持度</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#92-%E7%A1%AE%E8%AE%A4%E6%94%AF%E6%8C%81c11marco-span-stylecolororange__cplusplusspan"><span class="nav-text"> 9.2 确认支持C++11：marco __cplusplus</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#93-%E4%B8%89%E5%A4%A7%E4%B8%BB%E9%A2%98"><span class="nav-text"> 9.3 三大主题</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#931-variadic-templatessince-c11"><span class="nav-text"> 9.3.1 variadic templates（since C++11）</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#932-autosince-c11"><span class="nav-text"> 9.3.2 auto(since C++11)</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#933-ranged-base-span-stylecolorblueforspan-since-c11"><span class="nav-text"> 9.3.3 ranged-base for (since C++11)</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#94-reference"><span class="nav-text"> 9.4 reference</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#95-reference%E7%9A%84%E5%B8%B8%E8%A7%81%E7%94%A8%E9%80%94"><span class="nav-text"> 9.5 reference的常见用途</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%8D%81-object-model"><span class="nav-text"> 十、object model</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#101-%E5%AF%B9%E8%B1%A1%E6%A8%A1%E5%9E%8Bobject-model%E5%85%B3%E4%BA%8E-vptr-%E5%92%8C-vtbl"><span class="nav-text"> 10.1 对象模型（Object Model）：关于 vptr 和 vtbl</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#102-%E5%AF%B9%E8%B1%A1%E6%A8%A1%E5%9E%8Bobject-model%E5%85%B3%E4%BA%8E-this"><span class="nav-text"> 10.2 对象模型（Object Model）：关于 this</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#103-%E5%AF%B9%E8%B1%A1%E6%A8%A1%E5%9E%8Bobject-model%E5%85%B3%E4%BA%8Edynamic-binding"><span class="nav-text"> 10.3 对象模型（Object Model）：关于Dynamic Binding</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%8D%81%E4%B8%80-%E8%B0%88%E8%B0%88const"><span class="nav-text"> 十一、谈谈const</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%8D%81%E4%BA%8C-%E5%85%B3%E4%BA%8Enewdelete"><span class="nav-text"> 十二、关于new，delete</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#121-%E5%9B%9E%E9%A1%BE"><span class="nav-text"> 12.1 回顾</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#122-%E9%87%8D%E8%BD%BDoperator-new-opeartor-delete-operator-new-operator-delete"><span class="nav-text"> 12.2 重载::operator new, ::opeartor delete, ::operator new[], ::operator delete[]</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#123-%E9%87%8D%E8%BD%BDmember-operator-newdelete"><span class="nav-text"> 12.3 重载member operator new&#x2F;delete</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#124-%E9%87%8D%E8%BD%BDmember-operator-newdelete"><span class="nav-text"> 12.4 重载member operator new[]&#x2F;delete[]</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#125-%E7%A4%BA%E4%BE%8B"><span class="nav-text"> 12.5 示例</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#126-%E9%87%8D%E8%BD%BD-new-delete"><span class="nav-text"> 12.6 重载 new(), delete()</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#127-basic_string-%E4%BD%BF%E7%94%A8-newextra-%E6%89%A9%E5%85%85%E7%94%B3%E8%AF%B7%E9%87%8F"><span class="nav-text"> 12.7 basic_string 使用 new(extra) 扩充申请量</span></a></li></ol></li></ol></div>
      </div>
      <!--/noindex-->
     
      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="Maureen"
      src="/images/stan.jpeg">
  <p class="site-author-name" itemprop="name">Maureen</p>
  <div class="site-description" itemprop="description">心之所向，素履以往</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">7</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">7</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">2</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/maureenLiu" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;maureenLiu" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://blog.csdn.net/u011386173?spm=1000.2115.3001.5343" title="CSDN → https:&#x2F;&#x2F;blog.csdn.net&#x2F;u011386173?spm&#x3D;1000.2115.3001.5343" rel="noopener" target="_blank"><i class="crosshairs fa-fw"></i>CSDN</a>
      </span>
      <span class="links-of-author-item">
        <a href="mailto:maureen@qq.com" title="E-Mail → mailto:maureen@qq.com" rel="noopener" target="_blank"><i class="fa fa-envelope fa-fw"></i>E-Mail</a>
      </span>
  </div>
  <div class="cc-license motion-element" itemprop="license">
    <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" class="cc-opacity" rel="noopener" target="_blank"><img src="/images/cc-by-nc-sa.svg" alt="Creative Commons"></a>
  </div>



      </div>

        <div id="music163player"> 
            <iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width=330 height=86 src="//music.163.com/outchain/player?type=2&id=1475596788&auto=1&height=66"></iframe> 
        </div>
        <div class="back-to-top motion-element">
          <i class="fa fa-arrow-up"></i>
          <span>0%</span>
        </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 2021 – 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Maureen</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-area"></i>
    </span>
      <span class="post-meta-item-text">站点总字数：</span>
    <span title="站点总字数">307k</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
      <span class="post-meta-item-text">站点阅读时长 &asymp;</span>
    <span title="站点阅读时长">4:39</span>
</div>

        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>




  




  
<script src="/js/local-search.js"></script>













  

  


<script>
NexT.utils.loadComments(document.querySelector('#valine-comments'), () => {
  NexT.utils.getScript('//unpkg.com/valine/dist/Valine.min.js', () => {
    var GUEST = ['nick', 'mail', 'link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item => {
      return GUEST.includes(item);
    });
    new Valine({
      el         : '#valine-comments',
      verify     : false,
      notify     : false,
      appId      : '7A7ruXkEvS4VKjoTaajLunbw-9Nh9j0Va',
      appKey     : 'E4svxhhfVsrC9eCyM8YfT8uq',
      placeholder: "Just go go",
      avatar     : 'mm',
      meta       : guest,
      pageSize   : '10' || 10,
      visitor    : false,
      lang       : 'zh-cn' || 'zh-cn',
      path       : location.pathname,
      recordIP   : false,
      serverURLs : ''
    });
  }, window.Valine);
});
</script>

<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"log":false,"pluginJsPath":"lib/","pluginModelPath":"assets/","pluginRootPath":"live2dw/","tagMode":false});</script></body>
</html>

<!-- 页面点击小红心 -->
<script type="text/javascript" src="/js/clicklove.js"></script>
